package ExtendsStudy.demo_08;

public class Test {
    public static void main(String[] args) {
        feedAnimals(new Cat());
        feedAnimals(new Dog());

    }

    public static void feedAnimals(Animal animal){
        animal.eat();
        if (animal instanceof Cat c){
            c.catchBlack();
        }
        if (animal instanceof Dog d){
            d.play();
        }
    }
}

abstract class Animal{
    public abstract void eat();
}

class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("猫吃只因");
    }

    public void catchBlack(){
        System.out.println("猫抓只因");
    }
}

class Dog extends Animal{

    @Override
    public void eat() {
        System.out.println("狗吃只因角");
    }

    public void play(){
        System.out.println("喜欢穿背带裤 打篮球");
    }
}
